<template>
  <div class="cartcontrol">
    <transition name="move">
      <div class="iconfont icon-add" @click.stop.prevent="subCart" v-show="food.count"></div>
    </transition>

    <div class="cart-count">{{food.count}}</div>
    <div class="iconfont icon-add" @click.stop.prevent="addCart">
      <i class="bg"></i>
    </div>
  </div>
</template>
<script>
// 因为没有count这个东西，所以需要用vue提供的API的set进行添加
import Vue from "vue";
export default {
  props: {
    food: {
      type: Object
    }
  },

  created() {
    //   注意要使用set先要click为true
    click: true;
  },
  methods: {
    subCart() {
      this.food.count--;
    },
    addCart() {
      if (!this.food.count) {
        // this.food是添加的对象 conunt是添加的key值 ，1是添加的值
        Vue.set(this.food, "count", 1);
      } else {
        this.food.count++;
      }
    }
  }
};
</script>
<style lang="less" scope>
.iconfont,
.cart-count {
  display: inline-block;
}
.icon-add:before {
  font-size: 21px;
  color: rgb(52, 55, 56);
  padding: 0 5px;
}
.move-enter-active,
.move-leave-active {
  transition: all 0.1s linear;
}
.move-enter,
.move-leave-to {
  transform: translateX(20px) rotate(180deg);
}
</style>